home *** CD-ROM | disk | FTP | other *** search
/ Programming Sound Cards / Programming Sound Cards.iso / sound_19 / beep.c next >
Text File  |  1995-01-01  |  975b  |  56 lines

  1. #define LINT_ARGS
  2.  
  3. #include <dos.h>
  4. #include <conio.h>
  5.  
  6. #define  ONTONE  outp( 0x61, inp( 0x61 ) | 3 )
  7. #define  OFFTONE outp( 0x61, inp( 0x61 ) & 0xFC )
  8.  
  9. static void setfreq( count )
  10. unsigned int count;
  11. {
  12.  
  13.     outp( 0x43, 0xB6 );
  14.     outp( 0x42, (int) (count & 0xFF) );
  15.     outp( 0x42, (int) (count >> 8) );
  16. }
  17.  
  18. static unsigned long int getticks()
  19. {
  20. union   REGS regs;
  21.  
  22.     regs.h.ah = 0x00;
  23.     int86( 0x1A, ®s, ®s );
  24.     return( ((unsigned long int) regs.x.cx << 16) + regs.x.dx );
  25. }
  26.  
  27. void     beep( pitch, nticks )
  28. unsigned int pitch,nticks;
  29. {
  30. unsigned long int ticks,ticksa;
  31.  
  32.     setfreq( pitch );
  33.     ticksa = getticks();
  34.     while ( ( ticks = getticks() ) == ticksa )
  35.         ;
  36.     ONTONE;
  37.     ticks = ticks + (unsigned long int) nticks;
  38.     while ( getticks() < ticks )
  39.         ;
  40.     OFFTONE;
  41. }
  42.  
  43. #ifdef DEBUG
  44.  
  45. #include <stdlib.h>
  46. #include "beep.h"
  47.  
  48. void main()
  49. {
  50.  
  51.     beep( 200, 1 );
  52.     exit(0);
  53. }
  54.  
  55. #endif
  56.